#ifndef _MPEG4CODEC_H_
#define _MPEG4CODEC_H_
#include <inttypes.h>
extern "C" {
#include <x264.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
}

#include "codecs.h"
#include <list>
using namespace std;

class H264Decoder : public VideoDecoder
{
public:
	H264Decoder();
	virtual ~H264Decoder();
	virtual int DecodePacket(BYTE *in,DWORD len,int lost,int last);
	
	virtual int GetWidth()	{return ctx->width;};
	virtual int GetHeight()	{return ctx->height;};
	virtual BYTE* GetFrame(){return buffer;};
private:
	AVCodec 		*codec;
	AVCodecContext	*ctx;
	AVFrame			*picture;
	BYTE*			buffer;
	int				bufLen;
	DWORD 		bufSize;
	BYTE*		frame;
	DWORD		frameSize;
	BYTE		src;
};

class H264Encoder : public VideoEncoder
{
public:
	H264Encoder(int quality,int fillLevel);
	virtual ~H264Encoder();

	virtual int EncodeFrame(BYTE *in,DWORD len);
	virtual int FastPictureUpdate();
	virtual int GetNextPacket(BYTE *out,DWORD &len);
	virtual int SetSize(int width,int height);
	virtual int SetFrameRate(int fps,int kbits);

private:
	int OpenCodec();

	x264_t*		enc;
	x264_param_t    params;
	x264_nal_t*	nals;
	x264_picture_t  pic;
	x264_picture_t 	pic_out;

	int curNal;
	int numNals;
	int width;
	int height;
	int numPixels;
	int bitrate;
	int fps;
	int format;
	int opened;
	int intraPeriod;
	int pts;

};

#endif
